<!--
 * @Author: Shususumu
 * @Date: 2020-10-16 11:09:30
 * @LastEditTime: 2020-10-20 17:14:43
 * @FilePath: \campusPTjobs\src\views\check\cashcheck.vue
-->
<template>
  <div id="cash">
    <!-- 表格 -->
    <template>
      <el-table :data="cashList" stripe style="width: 100%">
        <el-table-column fixed prop="id" label="编号" width="80">
        </el-table-column>
        <el-table-column fixed prop="money" label="金额" width="150">
        </el-table-column>
        <el-table-column fixed prop="type" label="类型" width="150">
        </el-table-column>
        <el-table-column prop="description" label="描述"> </el-table-column>
        <el-table-column fixed prop="userId" label="员工ID" width="150">
        </el-table-column>
        <el-table-column prop="transferAccounts" label="凭证" width="120">
          <template slot-scope="scope">
            <el-button
              @click="
                (dialogVisible = true), Accounts(scope.row.transferAccounts)
              "
              type="text"
              size="small"
              >查看凭证</el-button
            >
          </template>
        </el-table-column>
        <el-table-column prop="statustos" label="状态" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button
              @click="(dialogFormVisible = true), check(scope.row)"
              type="text"
              size="small"
              :disabled="
                scope.row.status == '1' || scope.row.status == '0'
                  ? true
                  : false
              "
              >审核</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 分页 -->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[6, 8, 10, 12]"
      :page-size="6"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <!-- 凭证模态框 -->
    <el-dialog title="凭证" :visible.sync="dialogVisible" width="30%"
      ><div class="demo-image__error">
        <div class="block">
          <span class="demonstration"></span>
          <el-image>
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 模态框 -->
    <el-dialog title="提现审核" :visible.sync="dialogFormVisible">
      <el-form :model="form" ref="waiterform">
        <el-form-item label="编号" :label-width="formLabelWidth">{{
          form.id
        }}</el-form-item>
        <el-form-item label="金额" :label-width="formLabelWidth"
          >{{ form.money }}
        </el-form-item>
        <el-form-item label="类型" :label-width="formLabelWidth"
          >{{ form.type }}
        </el-form-item>
        <el-form-item label="描述" :label-width="formLabelWidth"
          >{{ form.description }}
        </el-form-item>
        <el-form-item label="员工ID" :label-width="formLabelWidth"
          >{{ form.userId }}
        </el-form-item>
        <el-form-item label="凭证" :label-width="formLabelWidth"
          >{{ form.transferAccounts }}
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="warning"
          @click="(dialogFormVisible = false), reauditing()"
          >不通过</el-button
        >
        <el-button
          type="success"
          @click="(dialogFormVisible = false), auditing()"
          >通过</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import qs from "querystring";
export default {
  data() {
    return {
      cashs: [],
      currentPage: 1,
      total: 1,
      pageSize: 6,
      dialogVisible: false,
      src: "",
      form: {
        id: "",
        description: "",
        money: "",
        status: "",
        transactionTime: "",
        transferAccounts: "",
        type: "",
        userId: "",
      },
      dialogFormVisible: false,
      formLabelWidth: "100px",
    };
  },
  computed: {
    cashList() {
      this.cashs.forEach((item) => {
        if (item.status == "1") {
          item.statustos = "审核通过";
        } else if (item.status == "0") {
          item.statustos = "审核未通过";
        } else {
          item.statustos = "未审核";
        }
      });
      this.cashs.filter((item) => {
        item.type = "提现";
      });
      return this.cashs;
    },
  },
  methods: {
    // 全局封装分页查询
    findquery() {
      var pageobj = { page: this.currentPage - 1, pageSize: this.pageSize };
      pageobj = qs.stringify(pageobj);
      this.$axios.post("/waiter/queryShou", pageobj).then((res) => {
        // console.log(res);
        this.cashs = res.data.data.list;
        this.total = res.data.data.total;
      });
    },
    //查看凭证
    Accounts(src) {
      this.src = src;
    },
    //审核功能
    check(row) {
      this.form = {
        id: row.id,
        description: row.description,
        money: row.money,
        status: row.status,
        transactionTime: row.transactionTime,
        transferAccounts: row.transferAccounts,
        type: row.type,
        userId: row.userId,
      };
    },
    // 封装
    Examine() {
      var self = this;
      this.$axios
        .post("/waiter/waiterexamine", self.form, {
          headers: {
            "Content-Type": "application/json",
          },
        })
        .then((res) => {
          if (res.data.status == 200) {
            //保存成功
            //1.关闭模态框

            //2.刷新页面
            self.findquery();
            //3.提示用户保存成功-弹框
            this.$message({
              message: "审核成功",
              type: "success",
            });
          } else {
            //保存失败
            this.$message.error("审核失败");
          }
        });
    },
    // 审核不通过
    reauditing() {
      this.form.status = "0";
      this.Examine();
    },
    //审核通过
    auditing() {
      this.form.status = "1";
      this.Examine();
    },
    //分页功能
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.findquery();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.findquery();
    },
  },
  created() {
    this.findquery();
  },
};
</script>
<style lang="scss" scoped>
#cash {
  margin: 18px;
}
.block {
  width: 150px;
  height: 100px;
  background-color: aquamarine;
}
</style>    